//
//  CheckSelfMessageViewController.m
//  Fangmm
//
//  Created by ChaoZhou on 16/3/3.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "CheckSelfMessageViewController.h"
#import "BecomeRoomChiefViewController.h"
#import "PersonCentreViewController.h"
#import "SucceedToChiefViewController.h"
#import "SucceedToApplyViewController.h"

#import <SDWebImage/UIImageView+WebCache.h>
#import <SDWebImage/UIButton+WebCache.h>
#import <objc/runtime.h>

#import "ACMacros.h"
#import "HttpServer.h"
#import "User.h"


@interface CheckSelfMessageViewController ()

@end

@implementation CheckSelfMessageViewController {
    User *user;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureView];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewWillAppear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    self.navigationController.navigationBarHidden = true;
    user = [User sharedUser];

}

- (void)viewWillDisappear:(BOOL)animated {
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    self.navigationController.navigationBarHidden = false;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - Configuring the view’s layout behavior
- (void)configureView {
    user = [User sharedUser];
    int i;
    unsigned int propertyCount = 0;
    objc_property_t *propertyList = class_copyPropertyList([User class], &propertyCount);
    for (i = 0; i < propertyCount; i++ ) {
        objc_property_t *thisProperty = propertyList + i;
        const char* propertyName = property_getName(*thisProperty);
        NSLog(@"Person has a property: '%s'", propertyName);
    }
    
    [self.avatarImageView sd_setImageWithURL:[NSURL URLWithString:user.avatar]];
    [self.nameLabel setText:user.name];
    [self.infoLabel setText:[NSString stringWithFormat:@"%d后 %@",user.ageGroup, user.constellation]];
    [self.professionLabel setText:[NSString stringWithFormat:@"%@ - %@",user.industry, user.profession]];
    if (user.certification) {
        [self.checkImage setImage:[UIImage imageNamed:@"check_ID-44-36"]];
        for (UILabel *label in self.checkLabels) {
            [label setTextColor:RGBACOLOR(255, 118, 108, 1)];
            if ([label isEqual:self.checkLabels.lastObject]) {
                [label setText:@"身份信息已认证通过"];
            }
        }
    } else {
        [self.checkImage setImage:[UIImage imageNamed:@"check_ID_dim-44-36"]];
        for (UILabel *label in self.checkLabels) {
            [label setTextColor:RGBACOLOR(160, 160, 160, 1)];
            if ([label isEqual:self.checkLabels.lastObject]) {
                [label setText:@"身份信息未认证通过"];
            }
        }
    }
    if (user.enterpriseAuth) {
        [self.companyAuthImage setImage:[UIImage imageNamed:@"check_company"]];
        for (UILabel *label in self.companyAuthLabels) {
            [label setTextColor:RGBACOLOR(255, 118, 108, 1)];
            if ([label isEqual:self.checkLabels.lastObject]) {
                [label setText:@"企业信息已认证通过"];
            }
        }
    } else {
        [self.companyAuthImage setImage:[UIImage imageNamed:@"check_company_dim"]];
        for (UILabel *label in self.companyAuthLabels) {
            [label setTextColor:RGBACOLOR(160, 160, 160, 1)];
            if ([label isEqual:self.checkLabels.lastObject]) {
                [label setText:@"企业信息未认证通过"];
            }
        }
    }
    for (int i = 0; i < user.tags.count; i++) {
        if (user.tags.count <= self.tagsLabels.count) {
            UILabel *label = self.tagsLabels[i];
            [label.layer setBorderColor:[[UIColor whiteColor] CGColor]];
            [label setText:user.tags[i]];
        }
    }
}

- (IBAction)clickToEdit:(UIButton *)sender {
    PersonCentreViewController *personCentreVC = [[PersonCentreViewController alloc]initWithNibName:@"PersonCentreViewController" bundle:nil];
    [self.navigationController pushViewController:personCentreVC animated:true];
//    personCentreVC.navigationController.navigationBarHidden = false;
}

- (IBAction)clickToNextView:(UIButton *)sender {
    if ([self.passingType isEqualToString:@"join"]) {
        SucceedToApplyViewController *succeedToApplyVC = [[SucceedToApplyViewController alloc]initWithNibName:@"SucceedToApplyViewController" bundle:nil];
        [self.navigationController pushViewController:succeedToApplyVC animated:true];
    } else if ([self.passingType isEqualToString:@"create"]) {
        SucceedToChiefViewController *succeedToChiefVC = [[SucceedToChiefViewController alloc]initWithNibName:@"SucceedToChiefViewController" bundle:nil];
        succeedToChiefVC.teamId = self.passingTeamId;
        [self.navigationController pushViewController:succeedToChiefVC animated:true];
    }
    
}

- (IBAction)clickToPopBack:(UIButton *)sender {
    if ([[[self.navigationController childViewControllers] class]containsObject:[BecomeRoomChiefViewController class]]) {
         [self.navigationController  popViewControllerAnimated:true];
    } else {
        [self dismissViewControllerAnimated:true completion:^{
        }];
    }
   
}

@end
